package com.netposa.datawarehouse.statistics.controller;

import com.netposa.appwebres.WebResCallback;
import com.netposa.appwebres.common.WebResCriteria;
import com.netposa.appwebres.common.WebResInfo;
import com.netposa.appwebres.exception.WebResException;
import com.netposa.datawarehouse.statistics.StatisticsClient;
import com.netposa.datawarehouse.statistics.service.HomeService;
import com.netposa.datawarehouse.statistics.service.LoginService;
import com.netposa.npwonder.base.util.RequestUtil;
import com.netposa.npwonder.base.util.ThreadLocalUtil;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import org.redisson.api.RMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({"/home"})
public class HomePageController {
   @Autowired
   private LoginService loginService;
   @Autowired
   private HomeService homeService;
   @Autowired
   private StatisticsClient statisticsClient;

   @GetMapping({"/login_count"})
   public WebResInfo loginCount() {
      return (new WebResCallback() {
         public void execute(WebResCriteria criteria, Object... params) {
            criteria.addSingleResult(HomePageController.this.loginService.loginCount());
         }
      }).sendRequest(new Object[0]);
   }

   @GetMapping({"/vehicle_count"})
   public WebResInfo vehicleCount() {
      return (new WebResCallback() {
         public void execute(WebResCriteria webResCriteria, Object... objects) {
            Map redisMap = HomePageController.this.statisticsClient.typeHourCount();
            Map map = new HashMap();
            Map resultMap = new HashMap();
            Map chartData = new HashMap();

            for(int i = 0; i < 24; ++i) {
               if (i < 10) {
                  resultMap.put("0" + i, 0L);
               } else {
                  resultMap.put("" + i, 0L);
               }
            }

            if (redisMap != null && redisMap.size() > 0) {
               Set redisKey = redisMap.keySet();
               Iterator var8 = redisKey.iterator();

               String s;
               while(var8.hasNext()) {
                  s = (String)var8.next();
                  if (s.endsWith("vehicle")) {
                     map.put(s, redisMap.get(s));
                  }
               }

               var8 = map.keySet().iterator();

               while(var8.hasNext()) {
                  s = (String)var8.next();
                  RMap rMap = (RMap)map.get(s);
                  long count = 0L;

                  String deviceId;
                  for(Iterator var13 = rMap.keySet().iterator(); var13.hasNext(); count += (Long)rMap.get(deviceId)) {
                     deviceId = (String)var13.next();
                  }

                  String[] split = s.split(":");
                  deviceId = split[1].substring(split[1].length() - 2, split[1].length());
                  long l = (Long)resultMap.get(deviceId) + count;
                  chartData.put(deviceId, l);
               }

               var8 = resultMap.keySet().iterator();

               while(var8.hasNext()) {
                  s = (String)var8.next();
                  if (!chartData.containsKey(s)) {
                     chartData.put(s, resultMap.get(s));
                  }
               }
            }

            webResCriteria.addSingleResult(chartData);
         }
      }).sendRequest(new Object[0]);
   }

   /** @deprecated */
   @Deprecated
   @GetMapping({"/zfyc_count"})
   public WebResInfo zfycCount(HttpServletRequest request) {
      ThreadLocalUtil.setTokenId(RequestUtil.getTokenId(request));
      return (new WebResCallback() {
         public void execute(WebResCriteria criteria, Object... params) {
            try {
               criteria.addSingleResult(HomePageController.this.homeService.zfycCount());
            } catch (Exception var4) {
               throw new WebResException("500");
            }
         }
      }).sendRequest(new Object[0]);
   }

   /** @deprecated */
   @Deprecated
   @GetMapping({"/illegal_count"})
   public WebResInfo illegalCount(HttpServletRequest request) {
      ThreadLocalUtil.setTokenId(RequestUtil.getTokenId(request));
      return (new WebResCallback() {
         public void execute(WebResCriteria criteria, Object... params) {
            try {
               criteria.addSingleResult(HomePageController.this.homeService.illegalCount());
            } catch (Exception var4) {
               throw new WebResException("500");
            }
         }
      }).sendRequest(new Object[0]);
   }

   /** @deprecated */
   @Deprecated
   @GetMapping({"/kcddh_count"})
   public WebResInfo kcddhCount(HttpServletRequest request) {
      ThreadLocalUtil.setTokenId(RequestUtil.getTokenId(request));
      return (new WebResCallback() {
         public void execute(WebResCriteria criteria, Object... params) {
            try {
               criteria.addSingleResult(HomePageController.this.homeService.kcddhCount());
            } catch (Exception var4) {
               throw new WebResException("500");
            }
         }
      }).sendRequest(new Object[0]);
   }

   /** @deprecated */
   @Deprecated
   @GetMapping({"/wxaqd_count"})
   public WebResInfo wxaqdCount(HttpServletRequest request) {
      ThreadLocalUtil.setTokenId(RequestUtil.getTokenId(request));
      return (new WebResCallback() {
         public void execute(WebResCriteria criteria, Object... params) {
            try {
               criteria.addSingleResult(HomePageController.this.homeService.wxaqdCount());
            } catch (Exception var4) {
               throw new WebResException("500");
            }
         }
      }).sendRequest(new Object[0]);
   }

   /** @deprecated */
   @Deprecated
   @GetMapping({"/tpc_count"})
   public WebResInfo tpcCount(HttpServletRequest request) {
      ThreadLocalUtil.setTokenId(RequestUtil.getTokenId(request));
      return (new WebResCallback() {
         public void execute(WebResCriteria criteria, Object... params) {
            try {
               criteria.addSingleResult(HomePageController.this.homeService.tpcCount());
            } catch (Exception var4) {
               throw new WebResException("500");
            }
         }
      }).sendRequest(new Object[0]);
   }
}
